/*************************************************************************
	> File Name: P1440.cpp
	> Author: yufangze
	> Mail: 2224590123@qq.com
	> Created Time: 2025-01-02 15:51:28
 ************************************************************************/

#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <cstdio>
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> arr(n + 1, 0);
    for (int i = 1; i <= n; i++) {
        cin >> arr[i];
    }
    printf("%d\n", 0);
    deque<int> q;
    for (int i = 1; i < n; i++) {
        while (!q.empty() && arr[i] <= arr[q.back()]) q.pop_back();
        q.push_back(i);
        printf("%d\n", arr[q.front()]);
        if (i - q.front() + 1 == m) {
            q.pop_front();
        }
    }
    return 0;
}
